package com.spatio.serving.basic.service.template.common.util;

import com.spatio.serving.basic.service.template.common.domain.UserInfoDo;
import com.spatio.serving.basic.service.template.common.domain.UserLoginDo;

import java.util.HashMap;
import java.util.Map;

public class ComputeCaUtils {

    private static double BMR;
    private static double AMR;
    private static Map<Integer, Double> waterMap;
    private static Map<Integer, Double> exerMap;
    //计算基础代谢
    public static double computeAMR(UserInfoDo user){
        waterMap=new HashMap<>();
        waterMap.put(0, 0.95);
        waterMap.put(1, 1.00);
        waterMap.put(2, 1.05);
        waterMap.put(3, 1.10);
        exerMap = new HashMap<>();
        exerMap.put(0, 1.1);
        exerMap.put(1, 1.2);
        exerMap.put(2, 1.375);
        exerMap.put(3, 1.55);
        String gender= user.getGender();
        Integer age= user.getAge(); //年龄
        Double height= user.getHeight();//身高
        Double weight= user.getWeight(); //体重
        Integer water= user.getWater_fre();
        Integer exercise=user.getExercise_fre();
        if(gender.equals("男")){
            BMR=88.362+(13.397*weight)+4.799*height-5.6778*age;
        }else {
            BMR=447.593+(9.247*weight)+3.098*height-4.330*age;
        }
        AMR=BMR*waterMap.get(water)*exerMap.get(exercise);
        return AMR;
    }

    public static double recomCalories(UserInfoDo user){
        Double weight=user.getWeight();
        Double tatgetWeights=user.getTarget_weight();
        Double AMR=computeAMR(user);
        Double changeperWeek=user.getChange_per_week();
        Double targetCalories;
        boolean isLoss;
        isLoss=((weight-tatgetWeights)>=0);
        if(isLoss){
            targetCalories=AMR-1100*changeperWeek;
        }else {
            targetCalories=AMR+1100*changeperWeek;
        }
        return targetCalories;
    }

    public static UserInfoDo recomStatics(UserInfoDo user){
        Double targetCalories=recomCalories(user);
        Double targetProtein=targetCalories*0.55*0.25;
        Double targetFat=targetCalories*0.25*0.25;
        Double targetCarbs=targetCalories*0.20*0.25;
        user.setTarget_proteins(targetProtein);
        user.setTarget_fats(targetFat);
        user.setTarget_carbs(targetCarbs);
        user.setTarget_calories(targetCalories);
        return user;
    }


}
